﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace DDD.GPT
{
    public static class ServiceCollectionExtension
    {
        public static IServiceCollection AddChatGpt(this IServiceCollection services, IConfiguration configuration)
        {
            var handler = new HttpClientHandler();
            handler.ClientCertificateOptions = ClientCertificateOption.Manual;
            handler.ServerCertificateCustomValidationCallback =
                    (httpRequestMessage, cert, cetChain, policyErrors) =>
                    {
                        return true;
                    };

            services.AddTransient<ChatGptHandler>();
            services.AddHttpClient<ChatGptHttpClient>(c => new HttpClient(handler))
                .AddHttpMessageHandler<ChatGptHandler>();

            return services;
        }
    }
}
